package com.efast.dmom.mes.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.dmom.mes.bean.QualityCheck;
import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.entity.base.IModificationFlags;
import com.efast.dmom.mes.service.QualityCheckService;

@Controller
@RequestMapping("/check")
public class QualityCheckController {
	
	@Autowired
	private QualityCheckService qualityCheckService;
	
	@RequestMapping(value = "/checkAddOrEdit")
	public @ResponseBody ResultBean save(@RequestBody QualityCheck qualityCheck) {
		ResultBean resultBean = new ResultBean(true,' ');
		// Judge to add
		if (qualityCheck.getModificationFlag()== IModificationFlags.NEW) {
					return qualityCheckService.save(qualityCheck);
				// Judge to update
		} else if (qualityCheck.getModificationFlag() == IModificationFlags.MODIFIED) {
					return qualityCheckService.update(qualityCheck);
		}
		return resultBean;
	}
	@RequestMapping(value = "/batchDeleteById")
	public @ResponseBody ResultBean batchDeleteById(@RequestBody List<QualityCheck> list) {
		ResultBean batchDeleteById = qualityCheckService.batchDeleteByIds(list);
		return batchDeleteById;
	}
	
	@RequestMapping(value = "/getAllParentData")
	public @ResponseBody ResultBean getAllParentData () {
		ResultBean resultBean = new ResultBean(true);
		List<QualityCheck> allParentData = qualityCheckService.getAllParentData();
		resultBean.setObject(allParentData);
		return resultBean;
	}
	
	@RequestMapping(value = "/getChildByParentId")
	public @ResponseBody ResultBean getChildByParentId (@RequestBody QualityCheck qualityCheck) {
		ResultBean resultBean = new ResultBean(true);
		ResultBean childByParentId = qualityCheckService.getChildByParentId(qualityCheck);
		resultBean.setObject(childByParentId);
		return resultBean;
	}
	@RequestMapping(value = "/validateIfChildListById")
	public @ResponseBody ResultBean validateIfChildListById (@RequestBody List<QualityCheck> list) {
		ResultBean resultBean = new ResultBean(true);
		ResultBean childByParentId = qualityCheckService.validateIfChildListById(list);
		resultBean.setObject(childByParentId);
		return resultBean;
	}

}
